﻿using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using FunkeLab;

namespace AnyOffice.general.hrms.manage
{
    public partial class user_list : ModulePage
    {
        protected MyTreeViewItem nodeParent;
      

        private void LoadDept(ref MyTreeViewItem nodeParent, int DeptId)
        {
            DataTable table = new DepartmentDao().SelectChildAll(base.Conn, DeptId);
            UsersDao dao2 = new UsersDao();
            if (table.Rows.Count > 0)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    MyTreeViewItem item = new MyTreeViewItem();
                    item.Text = (table.Rows[i]["DeptName"] == DBNull.Value) ? "" : table.Rows[i]["DeptName"].ToString();
                    item.Link = "dept.aspx?dept_id=" + table.Rows[i]["DeptId"].ToString();
                    item.TargetFrame = "hrms";
                    item.Image = "/images/node_dept.gif";
                    DataTable table2 = new DataTable();//dao2.SelectBaseByDeptId(base.Conn, Convert.ToInt32(table.Rows[i]["DeptId"].ToString()));
                    if (table2.Rows.Count > 0)
                    {
                        for (int j = 0; j < table2.Rows.Count; j++)
                        {
                            MyTreeViewItem item2 = new MyTreeViewItem();
                            item2.Text = table2.Rows[j]["UserName"].ToString();
                            item2.Image = "/images/node_user.gif";
                            item2.Link = "hrms.aspx?user_id=" + table2.Rows[j]["UserId"].ToString() + "&dept_id=" + table.Rows[i]["DeptId"].ToString();
                            item2.TargetFrame = "hrms";
                            item.Items.Add(item2);
                        }
                    }
                    this.LoadDept(ref item, int.Parse(table.Rows[i]["DeptId"].ToString()));
                    nodeParent.Items.Add(item);
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                DataTable table = new DepartmentDao().SelectParentAll(base.Conn);
                UsersDao dao2 = new UsersDao();
                if (table.Rows.Count > 0)
                {
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        this.nodeParent = new MyTreeViewItem();
                        this.nodeParent.Text = (table.Rows[i]["DeptName"] == DBNull.Value) ? "" : table.Rows[i]["DeptName"].ToString();
                        this.nodeParent.Link = "dept.aspx?dept_id=" + table.Rows[i]["DeptId"].ToString();
                        this.nodeParent.TargetFrame = "hrms";
                        this.nodeParent.Image = "/images/node_dept.gif";
                        DataTable table2 = new DataTable();//dao2.SelectBaseByDeptId(base.Conn, Convert.ToInt32(table.Rows[i]["DeptId"].ToString()));
                        if (table2.Rows.Count > 0)
                        {
                            for (int j = 0; j < table2.Rows.Count; j++)
                            {
                                MyTreeViewItem item = new MyTreeViewItem();
                                item.Text = table2.Rows[j]["UserName"].ToString();
                                item.Image = "/images/node_user.gif";
                                item.Link = "hrms.aspx?user_id=" + table2.Rows[j]["UserId"].ToString() + "&dept_id=" + table.Rows[i]["DeptId"].ToString();
                                item.TargetFrame = "hrms";
                                this.nodeParent.Items.Add(item);
                            }
                        }
                        this.LoadDept(ref this.nodeParent, int.Parse(table.Rows[i]["DeptId"].ToString()));
                        this.TreeView1.Items.Add(this.nodeParent);
                    }
                }
            }
        } 

    }
}
